package hermesV3.protocols;

import hermesV3.agent.AbstractProtocol;
import hermesV3.agent.Interaction;

/**
 * This Protocol manages the communication in the PhantomEnties exchange between
 * the {@code LocalCoordinator}s (through the intermediary of the
 * {@code SpaceManager}).
 * 
 * @see it.unicam.cs.cosy.bioshape.core.components.LocalCoordinator
 * @see hermesV3.services.Space.SpaceManager
 * 
 * @author Federico Buti, Gaston Alanis, Matteo Micheletti, Andrea Piermarteri
 */
public class PhantomProtocol extends AbstractProtocol {
	/** Auto-generated serial ID */
	private static final long serialVersionUID = 5338161764057772696L;

	/** {@code Interaction} for sending entities for ownership check */
	public static final String INTERACTIONTARGETREQ = "TargetReq";
	/** Response {@code Interaction} to the first one (phantom) */
	public static final String INTERACTIONTARGETRESPPHANTOM = "TargetRespPhantom";
	/** Response {@code Interaction} to the first one (centring) */
	public static final String INTERACTIONTARGETRESPCENTERING = "TargetRespCentering";
	/** Response {@code Interaction} to the first one (out of bound) */
	public static final String INTERACTIONTARGETRESPOUTOFBOUND = "TargetRespOutOfBound";
	/** Response {@code Interaction} to eventual errors */
	public static final String INTERACTIONERROR = "Error";

	/** Declares {@code Interaction}s among {@link PhantomProtocol} actions. */
	public PhantomProtocol() {
		super("PhantomProtocol");

		String[] parameterNameTargetReq = new String[1];
		parameterNameTargetReq[0] = "TargetReq";
		Class<?>[] parameterTypeTargetReq = new Class<?>[1];
		parameterTypeTargetReq[0] = Object.class;
		Interaction targetReq = new Interaction(INTERACTIONTARGETREQ,
				INTERACTIONTARGETREQ, INTERACTIONTARGETREQ,
				parameterNameTargetReq, parameterTypeTargetReq);
		addInteraction(targetReq);

		String[] parameterNameTargetRespPhantom = new String[1];
		parameterNameTargetRespPhantom[0] = "TargetRespPhantom";
		Class<?>[] parameterTypeTargetRespPhantom = new Class[1];
		parameterTypeTargetRespPhantom[0] = Object.class;
		Interaction targetRespPhantom = new Interaction(
				INTERACTIONTARGETRESPPHANTOM, INTERACTIONTARGETRESPPHANTOM,
				INTERACTIONTARGETRESPPHANTOM, parameterNameTargetRespPhantom,
				parameterTypeTargetRespPhantom);
		addInteraction(targetRespPhantom);

		String[] parameterNameTargetRespCentering = new String[1];
		parameterNameTargetRespCentering[0] = "TargetRespCentering";
		Class<?>[] parameterTypeTargetRespCentering = new Class[1];
		parameterTypeTargetRespCentering[0] = Object.class;
		Interaction targetRespCentering = new Interaction(
				INTERACTIONTARGETRESPCENTERING, INTERACTIONTARGETRESPCENTERING,
				INTERACTIONTARGETRESPCENTERING,
				parameterNameTargetRespCentering,
				parameterTypeTargetRespCentering);
		addInteraction(targetRespCentering);

		String[] parameterNameTargetRespOutOfBound = new String[1];
		parameterNameTargetRespOutOfBound[0] = "TargetRespOutOfBound";
		Class<?>[] parameterTypeTargetRespOutOfBound = new Class[1];
		parameterTypeTargetRespOutOfBound[0] = Object.class;
		Interaction targetRespOutOfBound = new Interaction(
				INTERACTIONTARGETRESPOUTOFBOUND,
				INTERACTIONTARGETRESPOUTOFBOUND,
				INTERACTIONTARGETRESPOUTOFBOUND,
				parameterNameTargetRespOutOfBound,
				parameterTypeTargetRespOutOfBound);
		addInteraction(targetRespOutOfBound);

		String[] parameterNameError = new String[1];
		parameterNameError[0] = "Error";
		Class<?>[] parameterTypeError = new Class[1];
		parameterTypeError[0] = String.class;
		Interaction error = new Interaction(INTERACTIONERROR, INTERACTIONERROR,
				INTERACTIONERROR, parameterNameError, parameterTypeError);
		addInteraction(error);

		// link interactions
		addErrorLink(targetReq, error);
		addErrorLink(targetRespPhantom, error);
		addErrorLink(targetRespCentering, error);
		addErrorLink(targetRespOutOfBound, error);
	}
}